package com.huaxin.common.Entity;

import android.os.Parcel;
import android.os.Parcelable;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/11/24.
 * {"craftId":71,"craftName":"ORBAL","createTime":1474276204000,"fileCode":"2016919170948",
 * "fileSize":227889,"id":1,"imgUrl":"/uploads/mvg/4/2016919170948.png",
 * "mvgUrl":"/uploads/mvg/4/2016919170948.mvg","viewName":"qqq工艺图"}
 */

public class SVGViewDTO extends BaseDTO {

    private List<SvgListBean> svgList;

    public List<SvgListBean> getSvgList() {
        return svgList;
    }

    public void setSvgList(List<SvgListBean> svgList) {
        this.svgList = svgList;
    }

    public static class SvgListBean implements Parcelable {
        /**
         * mvgUrl : http://10.0.0.62:8084/uploads/mvg/20161219134030/2016919170989.mvg
         * imgUrl : http://10.0.0.62:8084/uploads/mvg/20161219134030/2016919170989.png
         * id : 1
         * fileSize : 151520
         * createTime : 1496327598000
         * viewName : 翠湖新水厂工艺图
         * fileCode : 2016919170989
         * imgPath :
         */
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        private String mvgUrl;
        private String imgUrl;
        private int    id;
        private int    fileSize;
        private long   createTime;
        private String viewName;
        private String fileCode;
        private String imgPath;

        private boolean isExist;

        public boolean isExist() {
            return isExist;
        }

        public void setExist(boolean exist) {
            isExist = exist;
        }

        public String getMvgUrl() {
            return mvgUrl;
        }

        public void setMvgUrl(String mvgUrl) {
            this.mvgUrl = mvgUrl;
        }

        public String getImgUrl() {
            return imgUrl;
        }

        public void setImgUrl(String imgUrl) {
            this.imgUrl = imgUrl;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getFileSize() {
            return formatFileSize( fileSize);
        }


        public String getCreateTime() {
            return format.format(new Date(createTime));
        }

        public void setCreateTime(long createTime) {
            this.createTime = createTime;
        }

        public String getViewName() {
            return viewName;
        }

        public void setViewName(String viewName) {
            this.viewName = viewName;
        }

        public String getFileCode() {
            return fileCode;
        }

        public void setFileCode(String fileCode) {
            this.fileCode = fileCode;
        }

        public String getImgPath() {
            return imgPath;
        }

        public void setImgPath(String imgPath) {
            this.imgPath = imgPath;
        }

        public  String formatFileSize(long fileS) {
            java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
            String fileSizeString = "";
            if (fileS < 1024) {
                fileSizeString = df.format((double) fileS) + "B";
            } else if (fileS < 1048576) {
                fileSizeString = df.format((double) fileS / 1024) + "KB";
            } else if (fileS < 1073741824) {
                fileSizeString = df.format((double) fileS / 1048576) + "MB";
            } else {
                fileSizeString = df.format((double) fileS / 1073741824) + "G";
            }
            return fileSizeString;
        }

        @Override
        public String toString() {
            return "SvgListBean{" +
                    "format=" + format +
                    ", mvgUrl='" + mvgUrl + '\'' +
                    ", imgUrl='" + imgUrl + '\'' +
                    ", id=" + id +
                    ", fileSize=" + fileSize +
                    ", createTime=" + createTime +
                    ", viewName='" + viewName + '\'' +
                    ", fileCode='" + fileCode + '\'' +
                    ", imgPath='" + imgPath + '\'' +
                    ", isExist=" + isExist +
                    '}';
        }

        public SvgListBean() {
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeSerializable(this.format);
            dest.writeString(this.mvgUrl);
            dest.writeString(this.imgUrl);
            dest.writeInt(this.id);
            dest.writeInt(this.fileSize);
            dest.writeLong(this.createTime);
            dest.writeString(this.viewName);
            dest.writeString(this.fileCode);
            dest.writeString(this.imgPath);
            dest.writeByte(this.isExist ? (byte) 1 : (byte) 0);
        }

        protected SvgListBean(Parcel in) {
            this.format = (SimpleDateFormat) in.readSerializable();
            this.mvgUrl = in.readString();
            this.imgUrl = in.readString();
            this.id = in.readInt();
            this.fileSize = in.readInt();
            this.createTime = in.readLong();
            this.viewName = in.readString();
            this.fileCode = in.readString();
            this.imgPath = in.readString();
            this.isExist = in.readByte() != 0;
        }

        public static final Creator<SvgListBean> CREATOR = new Creator<SvgListBean>() {
            @Override
            public SvgListBean createFromParcel(Parcel source) {
                return new SvgListBean(source);
            }

            @Override
            public SvgListBean[] newArray(int size) {
                return new SvgListBean[size];
            }
        };
    }

    @Override
    public String toString() {
        return "SVGViewDTO{" +
                "svgList=" + svgList +
                '}';
    }
}
